import { defineConfig, loadEnv } from "vite";
import vue from '@vitejs/plugin-vue'
import { resolve } from "path";

// https://vitejs.dev/config/
const getViteEnv = (mode, target) => {
  return loadEnv(mode, process.cwd())[target];
};
export default ({ mode }) => defineConfig({
  base: getViteEnv(mode, "VITE_APP_BASE_URL"), //必须和基座也就是主应用的activeRule值一致
  plugins: [vue()],
  build: {
    lib: {
      entry: "src/package/index.ts",
      name: "lzj-test-comp",
      fileName: "lzj-test-comp",
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          waterMarker: "lzj-test-comp",
        },
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"), // 设置 `@` 指向 `src` 目录
    },
    // 忽略后缀名的配置选项, 添加 .vue 选项时要记得原本默认忽略的选项也要手动写入
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData:
          '@use "./src/styles/variables.scss" as *;@import "./src/styles/mixins.scss";@import "./src/styles/function.scss";', //设置全局样式
      },
    },
  },
})
